import './index.scss'
import { searchAllDictionaries } from '@/api/public'
import { getCanChoosePage,getActivityPage } from '@/api/shoppingMall/feature'

export default {
  name: 'choose-feature',
  props: {
    isGetChooseData: { // 是否开始返回数据
      type: Boolean,
      default: false
    }
  },
  watch: {
    isGetChooseData() {
      if (!this.currentchooseFeatures.id) {
        this.$message.error('请选择微页面')
        return
      }
      this.$emit('chooseChooseFeaturesFun', {
        data: this.currentchooseFeatures
      })
    }
  },
  data() {
    return {
      selectCouponList: [],
      selectCampaignList: [],
      campaignSceneTypeCode: 'POINTS_MALLA_SCENE', // value: "积分商城":"POINTS_MALLA_SCENE"  "秒杀":"SECKILL_SCENE"
      couponSceneTypeCode: 'FULL_DISCOUNT_COUPON_SCENE',
      activeValue: 0,
      pageParms: {
        pageNum: 1,
        pageSize: 10,
        type: 0,
        campaignScene: 'POINTS_MALLA_SCENE',
        couponScene: 'FULL_DISCOUNT_COUPON_SCENE'
      },
      pageTab: '',
      list: [],
      option: {
        isPagination: true,
        isMenu: false,
        height: 260,
        paginationTotal: 10,
        paginationCurrent: 1,
        paginationSize: 10,
        highlightCurrentRow: true,
        column: [
          {
            label: '名称',
            prop: 'title',
            width: '280px',
            align: 'left'
          },
          {
            label: '描述',
            prop: 'description',
            width: '320px'
          },
          {
            label: '创建时间',
            prop: 'createTime',
            width: '150px'
          }
        ]
      },
      currentchooseFeatures: {}// 当前选择的
    }
  },
  created() {
    searchAllDictionaries({ type: 'page_type' }).then(res => {
      this.pageTab = res
      console.log('this.pageTab', this.pageTab)
    })
  },
  mounted () {
    this.getPageList(this.pageParms.type)
  },
  methods: {
    selectCouponChange(){},
    selectCampaignChange(){
      this.getPageList()
    },
    handleClick(tab, event) {
      this.pageParms.type = tab.name
      this.pageParms.pageNum = 1
        this.getPageList()
      console.log('tab.name', tab.name)
      console.log('event', event)
    },
    getPageList() {
      console.log('this.pageParms',this.pageParms.type)
      // this.pageParms.type = type
      if(this.pageParms.type === '3'){
        getActivityPage({...this.pageParms,campaignScene:this.campaignSceneTypeCode}).then(res => {
          res.records.forEach(item => {
            item.title = item.name
            item.type = 3
          })
          this.list = res.records
          this.option.paginationTotal = res.total
        })
      }else{
        getCanChoosePage(this.pageParms).then(res => {
          this.list = res.records
          this.option.paginationTotal = res.total
        })
      }

    },
    /** 单选*/
    currentRowChange(ev) {
      // console.log('ev', ev)
      this.currentchooseFeatures = ev
      this.$emit('chooseChooseFeaturesFun', {
        data: this.currentchooseFeatures
      })
    },
    pageCurrent(val) {
      // console.log('val', val.data.current)
      this.pageParms.pageNum = val.data.current
      this.option.paginationCurrent = val.data.current
      this.pageParms.pageSize = val.data.size
      this.getPageList()
    }
  }
}
